//
//  TweetImageViewController.m
//  Guazi
//
//  Created by koolearn on 11-8-2.
//  Copyright 2011年 __MyCompanyName__. All rights reserved.
//

#import "TweetImageViewController.h"
#import "TweetImageStore.h"


@implementation TweetImageViewController

@synthesize imageURL;


- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
        imageView = nil;
    }
    return self;
}


- (void)dealloc
{
    [imageURL release];
    [imageView release];
    [super dealloc];
}


- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle

// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView
{
    CGRect frame = [[UIScreen mainScreen] applicationFrame];
    UIView* contentView = [[UIView alloc] initWithFrame:frame];
    contentView.backgroundColor = [UIColor blackColor];
    self.view = contentView;
    [contentView release];
    
    UIImage* image = [[TweetImageStore sharedInstance] getTweetImage:imageURL size:CGSizeMake(320, 368) delegate:self];
    imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, image.size.width, image.size.height)];
    imageView.center = CGPointMake(160, 183);
    imageView.backgroundColor = self.view.backgroundColor;
    imageView.image = image;
    [self.view addSubview:imageView];
}


/*
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad
{
    [super viewDidLoad];
}
*/

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}


#pragma mark - ImageDownloader Delegate

- (void) imageDidGetNewImage:(UIImage*)image forURL:(NSString*)url
{
    imageView.frame = CGRectMake( (320 - image.size.width)/2, (368 - image.size.height)/2, image.size.width, image.size.height );
    imageView.image = image;
    [imageView setNeedsDisplay];
}



@end
